package com.miaowang.salad.jobqueue;

import com.alibaba.fastjson.JSON;
import com.miaowang.salad.data.OkHttpResponseData;
import com.miaowang.salad.net.OkHttpUtils;
import com.miaowang.salad.net.UrlUtils;
import com.path.android.jobqueue.Job;
import com.path.android.jobqueue.Params;
import com.path.android.jobqueue.RetryConstraint;

import de.greenrobot.event.EventBus;

/**
 * 修改车辆信息
 * @author weihe
 *
 */
public class NewOrChangeMyCarInfoJob extends Job {

	private String json;
	public NewOrChangeMyCarInfoJob(String json) {
		super(new Params(JobQueuePriority.PRIORITY_HIGH).groupBy(JobQueuePriority.JOBS_GROUP_USER).requireNetwork());
		this.json = json;
	}

	@Override
	public void onAdded() {

	}

	@Override
	protected void onCancel() {

	}

	@Override
	public void onRun() throws Throwable {
         String result = OkHttpUtils.post(UrlUtils.SEND_MY_INFO, json.toString());
         OkHttpResponseData responseData = JSON.parseObject(result, OkHttpResponseData.class);
         EventBus.getDefault().post(new JobEvents.JobSuccess<>(JobEvents.SEND_MY_INFO,responseData));
	}

	
	@Override
	protected boolean shouldReRunOnThrowable(Throwable throwable) {
		EventBus.getDefault().post(new JobEvents.JobSuccess<>(JobEvents.SEND_MY_INFO));
		return false;
	}
}
